package BanyuanClub.Work.Story.Six;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Text {
    public static void main(String[] args) {
        try(BufferedReader br = new BufferedReader(
                new FileReader("hero.txt"));
            BufferedWriter bw = new BufferedWriter(
                    new FileWriter("hero2.txt")
            )
        ){
            String s;
            List<Hero> list = new ArrayList<>();
            while ((s = br.readLine()) != null){
                String[] arr = s.split(",");
                list.add(new Hero(arr[0],Integer.parseInt(arr[1]),
                        arr[2].charAt(0),arr[3]));
                Collections.sort(list,(h1,h2)-> {return h2.getAge() - h1.getAge();});
                for (Hero hero:
                     list) {
//                    bw.write();
                    bw.newLine();
                    bw.flush();
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
